/*
 * Author: JoeM
 * Date: 2007/05/01
 * Tao Studio
 *
*/

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef _INC_LOGGER_H
#define _INC_LOGGER_H

#ifndef _WIN32_WINNT		// Allow use of features specific to Windows XP or later.                   
#define _WIN32_WINNT 0x0501	// Change this to the appropriate value to target other versions of Windows.
#endif	

#include <stdio.h>
#include <tchar.h>
#include <errno.h>
#include <windows.h>

#ifdef __cplusplus
extern "C" {
#endif
	
	/*
	 * Log subscriber signature, u can use it to specify ur log subscriber.
	 */
	typedef DWORD (WINAPI *logsubscriber)(TCHAR const *log);

	/*
	 * Configurate the log subscribers which u want to use. 
	 * And this routine must be called before log_output routine.
	 *
	 * If the routine succeeds, the return value is nonzero.
	 * If the routine fails, the returen value is zero.
	 */
	int config_log_subscribers(int subscribers_size, ...);

	/*
	 * Clean the log subscribers.
	 */
	void clean_log_subscribers(void);

	/*
	 * Log the message which ur want to logged to the log subscribers.
	 *
	 * If the routine succeeds, the return value is nonzero.
	 * If the routine fails, the return value is zero.
	 */
	int log_output(TCHAR const *category, TCHAR const *format, ...);

	/*
	 * When u want to use a file-log subscriber, u must call this routine
	 * before call config_log_subscribers routine.
	 * 
	 * If the routine succeeds, the return value is nonzero.
	 * If the routine fails, the return value is zero.
	 */
	int config_filelog_subscriber(TCHAR const *logfile_name, unsigned __int64 logfile_limit);

	/*
	 * Default debug-log subscriber.
	 * 
	 * If the routine succeeds, the return value is nonzero.
	 * If the routine fails, the return value is zero.
	 */
	DWORD WINAPI subscribe_dbglog(TCHAR const *log);

	/*
	 * Default file-log subscriber.
	 */
	DWORD WINAPI subscribe_filelog(TCHAR const *log);

#ifdef __cplusplus
}
#endif

#endif /* _INC_LOGGER_H */